# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=fava
pkgver=1.26.4
pkgrel=0
pkgdesc="Web interface for Beancount"
url="https://beancount.github.io/fava/"
arch="all !ppc64le" # limited by beancount
license="MIT"
depends="
	beancount
	python3
	py3-babel
	py3-flask
	py3-flask-babel
	py3-jinja2
	py3-werkzeug
	py3-cheroot
	py3-click
	py3-markdown2
	py3-ply
	py3-simplejson
	"
makedepends="
	npm
	nodejs
	py3-gpep517
	py3-setuptools
	py3-setuptools_scm
	py3-wheel
	"
checkdepends="py3-pytest"
subpackages="$pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/beancount/fava/archive/refs/tags/v$pkgver.tar.gz"

prepare() {
	default_prepare

	# static files aren't detected to be included in the wheel file
	echo "recursive-include src/fava *.html *.js *.md beancount_file" >> MANIFEST.in

	cd frontend
	npm install --no-progress
}

build() {
	cd frontend
	npm run build
	cd ..

	export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
	pybabel compile -d src/fava/translations
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl

	# test_cli.py requires fava to be available inside PATH
	.testenv/bin/python3 -m pytest --ignore=tests/test_cli.py
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

sha512sums="
4db046ec53704da417518e83344db1b9ff7c88698a65c1ed8cfebfda53af6b27ef1e0caf7de75c2d4eed42b73075be9bc221f53c3d7f422531c20f7aa2ba6357  fava-1.26.4.tar.gz
"
